package com.bm.server.service.impl;

import com.bm.server.dao.LoversDao;
import com.bm.server.dao.UserInfoDao;
import com.bm.common.dto.LoversDto;
import com.bm.server.entity.Lovers;
import com.bm.server.entity.UserInfo;
import com.bm.server.service.intf.LoversService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class LoversServiceImpl implements LoversService {
    @Resource
    private LoversDao loversDao;
    @Resource
    private UserInfoDao userInfoDao;


    @Override
    public List<Lovers> findLoversIds() {
        List<Lovers> loversIds = loversDao.findLoversIds();
        System.out.println(loversIds);

        return loversIds;
    }

    @Override
    public ArrayList<LoversDto> findLoversInfo(List<Lovers> loversIds)
   {

        ArrayList<LoversDto> loversDtos = new ArrayList<>();

        ArrayList<ArrayList<LoversDto>> lovers = new ArrayList<>();
        int size = loversIds.size();

        for (int i = 0 ; i < size ; i++){
            int idNan = loversIds.get(i).getUidNan();
            int idNv = loversIds.get(i).getUidNv();

            UserInfo loversNan = userInfoDao.selectById(idNan);
            UserInfo loversNv = userInfoDao.selectById(idNv);

            LoversDto loversNanDto = new LoversDto();
            LoversDto loversNvDto = new LoversDto();

            //情侣中男dto
            loversNanDto.setId(loversNan.getId());
            loversNanDto.setNickName(loversNan.getNickName());
            loversNanDto.setSex(loversNan.getSex());
            System.err.println(loversNan.getSex());
            loversNanDto.setHeadurl(loversNan.getHeadurl());
            //情侣中女dto
            loversNvDto.setId(loversNv.getId());
            loversNvDto.setNickName(loversNv.getNickName());
            loversNvDto.setSex(loversNv.getSex());
            System.err.println(loversNv.getSex());
            loversNvDto.setHeadurl(loversNv.getHeadurl());

            loversDtos.add(loversNanDto);
            loversDtos.add(loversNvDto);


        }
       return loversDtos;
    }
}
